﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.IsAnagram
{
    class MainProject
    {
        static void Main(string[] args)
        {
            string a = "ab";
            string b = "a";

            Console.WriteLine(IsAnagram(a,b));
            Console.ReadKey();
        }
        public static bool IsAnagram(string s, string t)
        {
            Dictionary<char, int> strDic = new Dictionary<char, int>();
            foreach (var item in s)
            {
                if (!strDic.ContainsKey(item))
                {
                    strDic.Add(item, 1);
                }
                else
                    strDic[item]++;
            }
            foreach (var item in t)
            {
                if (strDic.ContainsKey(item))
                {
                    strDic[item]--;
                    if (strDic[item]==0)
                        strDic.Remove(item);
                }
                else
                    return false;
            }
            if (strDic.Count>0)
            {
                return false;
            }
            return true;
        }
    }
}
